#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>

int main()
{
    int ret;
    int c;
    char buf[BUFSIZ];

    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    struct sockaddr_in server_addr;
    server_addr.sin_addr.s_addr = inet_addr("192.168.127.130");
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(9000);

    strcpy(buf, "hello world");
    ret = sendto(sockfd, buf, strlen(buf) + 1, 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
    if (ret == -1)
    {
        perror("sendto");
        exit(errno);
    }

    printf("send %d bytes\n", ret);

    ret = recv(sockfd, buf, sizeof(buf), 0);
    if (ret == -1)
    {
        perror("revcefrom");
        exit(errno);
    }

    printf("received %d bytes\n", ret);
    printf("received:%s\n", buf);

    return 0;
}